/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminUI.java
 *
 * Created on Aug 14, 2011, 11:14:09 AM
 */
package elevatormanagementsystem;

import elevatormanagementsystem.UCC.UCCSetupProgram;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Danny
 */
public class AdminUI extends javax.swing.JPanel {
    
    int maxFloorNumber;
    int minFloorNumber;

    /** Creates new form AdminUI */
    public AdminUI() {
        initComponents();   
        run();
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        numElevators = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        minFloorNum = new javax.swing.JTextField();
        maxFloorNum = new javax.swing.JTextField();
        configureBttn = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Elevator:");

        numElevators.setText("1");
        numElevators.setFocusable(false);
        numElevators.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                numElevatorsActionPerformed(evt);
            }
        });

        jLabel2.setText("Number of Elevators");

        jLabel3.setText("Minimum Floor");

        jLabel4.setText("Maximum Floor");

        configureBttn.setText("configure");
        configureBttn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configureBttnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(maxFloorNum, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                            .addComponent(minFloorNum)
                            .addComponent(numElevators))))
                .addContainerGap(32, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(116, Short.MAX_VALUE)
                .addComponent(configureBttn)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(numElevators, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(minFloorNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(maxFloorNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addComponent(configureBttn)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void configureBttnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configureBttnActionPerformed
    minFloorNumber =  Integer.parseInt(minFloorNum.getText());
    maxFloorNumber =  Integer.parseInt(maxFloorNum.getText());
    if (minFloorNumber > maxFloorNumber) {
        String errorMessage = "\"Error\"\n"
        + "It appears that your minimum floor value\n"
        + "is greater then your maximum floor value";
        JOptionPane.showMessageDialog(new JFrame(), errorMessage, "Invalid Comparison",
        JOptionPane.ERROR_MESSAGE);        
    }  
    else if (minFloorNumber < 1 || maxFloorNumber > 5) {
        JOptionPane.showMessageDialog(new JFrame(), "Either the min or max floor parameters are out of \n" +
               "bounds of the current scope", "Invalid Parameters",
        JOptionPane.ERROR_MESSAGE);
    }
    else {      
        System.out.println("Reached Success statement");
        Elevator e1 = new Elevator(minFloorNumber, maxFloorNumber);
        new UCCSetupProgram(e1, minFloorNumber, maxFloorNumber).Run();
    }
}//GEN-LAST:event_configureBttnActionPerformed

private void numElevatorsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numElevatorsActionPerformed

}//GEN-LAST:event_numElevatorsActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton configureBttn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField maxFloorNum;
    private javax.swing.JTextField minFloorNum;
    private javax.swing.JTextField numElevators;
    // End of variables declaration//GEN-END:variables

    private void run() {
        JFrame adminFrame = new JFrame();
        adminFrame.add(this);
        adminFrame.pack();
        adminFrame.setTitle("Admin UI");
        adminFrame.setVisible(true);
        System.out.println("Reached Run");
        adminFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

       
}
